package com.yhn.shortlink.admin.controller;

import com.yhn.shortlink.admin.service.LinkGroupService;
import com.yhn.shortlink.admin.dto.req.group.GroupSaveReqDTO;
import com.yhn.shortlink.admin.dto.req.group.GroupSortReqDTO;
import com.yhn.shortlink.admin.dto.req.group.GroupUpdateReqDTO;
import com.yhn.shortlink.admin.dto.resp.group.GroupRespDTO;
import com.yhn.shortlink.common.model.BaseResponse;
import com.yhn.shortlink.common.model.ResultUtils;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yhn
 * @version 1.0
 * @description
 * @date 2024/7/21 13:34
 */
@RestController
@RequestMapping("/group")
public class LinkGroupController {

    @Resource
    private LinkGroupService groupService;

    /**
     * 新增短链分组
     *
     * @return 用户信息
     */
    @PostMapping("/save")
    public BaseResponse<Boolean> saveGroup(@RequestBody GroupSaveReqDTO groupSaveReqDTO) {
        return ResultUtils.success(groupService.addGroup(groupSaveReqDTO.getName()));
    }

    /**
     * 查询短链分组
     */
    @GetMapping("/list")
    public BaseResponse<List<GroupRespDTO>> listGroup() {
        return ResultUtils.success(groupService.listGroup());
    }

    /**
     * 修改短链分组
     *
     * @return 用户信息
     */
    @PostMapping("/update")
    public BaseResponse<Boolean> updateGroup(@RequestBody GroupUpdateReqDTO groupSaveReqDTO) {
        return ResultUtils.success(groupService.updateGroup(groupSaveReqDTO));
    }

    /**
     * 删除短链分组
     *
     * @return 用户信息
     */
    @PostMapping("/delete")
    public BaseResponse<Boolean> deleteGroup(@RequestParam("gid") String gid) {
        return ResultUtils.success(groupService.deleteGroup(gid));
    }

    /**
     * 短链接排序
     *
     * @param groupSortReqs 要排序的短链接
     * @return 排序后的短链接
     */
    @PostMapping("/sort")
    public BaseResponse<Boolean> sortGroup(@RequestBody List<GroupSortReqDTO> groupSortReqs) {
        return ResultUtils.success(groupService.groupSort(groupSortReqs));
    }
}
